Skip to content

Conversation

slobodanadamovic
Copy link
Contributor

@slobodanadamovic slobodanadamovic commented Sep 30, 2025

Initially, the RemoteClusterTransportInterceptor#getProfileTransportFilters required remote-cluster security extensions to provide transport filters for all transport profiles. The method was too generic and not specific to only _remote_cluster transport profile. This meant that RCS extensions were free to decide which filter they wanted to "override" with its custom transport filter implementation. This turned out to be unnecessary, because RCS extensions only ever need to provide a custom implementation for the remote cluster profile. This refactoring removes the need to provide the "default" ServerTransportFilter in order for security to work.

Followups to:


  • Converted ServerTransportFilter to interface with a default implementation.
  • Refactored RemoteClusterTransportInterceptor to allow optionally providing only a custom remote cluster transport filter. It's no longer required from RCS extensions to provide the default ServerTransportFilter implementation.
  • Split transport interceptor and filter tests:
    • ServerTransportFilterTests became abstract and got split into two tests: CrossClusterAccessServerTransportFilterTests and DefaultServerTransportFilterTests
    • Cross-cluster access tests got extracted from SecurityServerTransportInterceptorTests into its own CrossClusterAccessTransportInterceptorTestsclass

 - Converted `ServerTransportFilter` to interface with the default
 implementation.
 - Refactoried `RemoteClusterTransportInterceptor` to allow optionally
 providing only a custom remote cluster transport profile filter.
- Split transport interceptor and filter tests
@slobodanadamovic slobodanadamovic added >refactoring :Security/Security Security issues without another label Team:Security Meta label for security team labels Sep 30, 2025
@elasticsearchmachine elasticsearchmachine added the serverless-linked Added by automation, don't add manually label Sep 30, 2025
@slobodanadamovic slobodanadamovic changed the title Refactor transport filters and remote cluster interceptor Refactor remote cluster interceptor Oct 1, 2025
@slobodanadamovic slobodanadamovic marked this pull request as ready for review October 1, 2025 06:47
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

@slobodanadamovic slobodanadamovic changed the title Refactor remote cluster interceptor Refactor remote cluster interceptor and tests Oct 1, 2025
import static org.elasticsearch.xpack.security.authc.CrossClusterAccessHeaders.CROSS_CLUSTER_ACCESS_CREDENTIALS_HEADER_KEY;

final class CrossClusterAccessServerTransportFilter extends ServerTransportFilter {
final class CrossClusterAccessServerTransportFilter extends DefaultServerTransportFilter implements ServerTransportFilter {
Copy link
Contributor

@jfreden jfreden Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implements ServerTransportFilter is implicit since CrossClusterAccessServerTransportFilter is a DefaultServerTransportFilter that in turn implements ServerTransportFilter.

Might be out of scope for this PR, but the inheritance here is a little confusing. CrossClusterAccessServerTransportFilter is only overriding the authenticate method which leads me to believe that the code in CrossClusterAccessServerTransportFilter actually belongs in CrossClusterAccessAuthenticationService and this class could be dropped for that reason.

Copy link
Contributor Author

@slobodanadamovic slobodanadamovic Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good point. Thanks for bringing this up. I think the end goal could be to have a single ServerTransportFilter implementation that accept a custom authentication service (CrossClusterAccessAuthenticationService or AuthenticationService). I like this idea, but that might be more involved at this point as it would require more refactoring. As a first step towards that, I could start by reverting the interface introduction, and later following up with generalizing the authentication part. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I didn't realize they were different interfaces, yes that makes it more difficult. One more thing that could be done in this PR is to move the logic into the CrossClusterAccessAuthenticationService and just do the authenticate call. I'll leave it up to you, might also make sense to not increase the scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, them being different interfaces with a different number of parameters makes it not that straightforward, but doable. In the interest of unblocking downstream work, I'd prefer to get back to this in a followup.

import static org.elasticsearch.xpack.security.authc.CrossClusterAccessHeaders.CROSS_CLUSTER_ACCESS_CREDENTIALS_HEADER_KEY;

final class CrossClusterAccessServerTransportFilter extends ServerTransportFilter {
final class CrossClusterAccessServerTransportFilter extends DefaultServerTransportFilter implements ServerTransportFilter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I didn't realize they were different interfaces, yes that makes it more difficult. One more thing that could be done in this PR is to move the logic into the CrossClusterAccessAuthenticationService and just do the authenticate call. I'll leave it up to you, might also make sense to not increase the scope.

@Override
public Map<String, ServerTransportFilter> getProfileTransportFilters(
Map<String, SslProfile> profileConfigurations,
public Optional<ServerTransportFilter> getRemoteProfileTransportFilter(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning Optional<ServerTransportFilter> is more of a preference here. We could as well return ServerTransportFilter and annotate the method as @Nullable

Copy link
Contributor

@jfreden jfreden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job on this! You probably want to wait for a review from someone familiar with CPS too, but LGTM!

Copy link
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Production code changes LGTM. Didn't read test code and I'd like to defer to @jfreden's review for that. Thanks!

slobodanadamovic and others added 5 commits October 6, 2025 14:09
…-transport-refactoring

# Conflicts:
#	x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/SecurityServerTransportInterceptorTests.java
@slobodanadamovic slobodanadamovic added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Oct 6, 2025
@elasticsearchmachine elasticsearchmachine merged commit 2b91dd5 into elastic:main Oct 6, 2025
40 checks passed
@slobodanadamovic slobodanadamovic deleted the security-transport-refactoring branch October 6, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >refactoring :Security/Security Security issues without another label serverless-linked Added by automation, don't add manually Team:Security Meta label for security team v9.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants